var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/defineProperty"), a = require("../../../@babel/runtime/helpers/typeof"), i = require("../../../@babel/runtime/helpers/asyncToGenerator"), o = getApp(), n = wx.getSystemInfoSync().windowHeight;

Component({
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        bottomShowBol: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        index: {
            type: null
        },
        btnFlag: {
            type: null
        },
        page_id: {
            type: null
        },
        store_id: {
            type: null
        }
    },
    observers: {
        btnFlag: function(t) {}
    },
    lifetimes: {
        attached: function() {
            var t = this;
            this.data.bottomShowBolIndex == this.data.index && setTimeout(function() {
                t.setData({
                    showTabs: !0
                });
            }, 200);
            var e = this.data.datas.list, a = [], i = [];
            e.forEach(function(t) {
                i.push(t.second_list), t.second_list[0] ? a.push(t.second_list[0].components) : a.push([]);
            });
            var o = [];
            i.forEach(function(t, e) {
                t.forEach(function(t, e) {
                    0 == e && (t.tabSelectShow = t.id);
                }), o.push(t);
            }), this.setData({
                infoDatas: a,
                allDatas: o
            });
        },
        detached: function() {}
    },
    ready: function() {},
    data: {
        intoSelect: 0,
        leftScrollTop: 0,
        rightScrollTop: 0,
        infoDatas: [],
        navDatas: [],
        showTabs: !1,
        leftPosShow: !1,
        isFixedArr: [],
        isLeftFixed: !1,
        listHeight: [],
        childPos: !1,
        height: n
    },
    methods: {
        tapChange: function(o) {
            var n = this;
            return i(t.default.mark(function i() {
                var s, l, c, r, d, h, u, f, p;
                return t.default.wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        return s = o.currentTarget.dataset.all, l = o.currentTarget.dataset.index, c = n.data.datas.list[l].second_list, 
                        d = (r = s).length - 1, h = r[r.length - 1].id, t.next = 8, n.tapchangeOne(d, c, h);

                      case 8:
                        for (u = t.sent, "object" == a(u) && (f = c.slice(u.ind, u.listinid)), p = 0; p < f.length; p++) f[p].tabSelectShow = u.tabShow;
                        n.setData(e({}, "allDatas[" + l + "]", f)), console.log(n.data.allDatas);

                      case 13:
                      case "end":
                        return t.stop();
                    }
                }, i);
            }))();
        },
        tapchangeOne: function(t, e, a) {
            return new Promise(function(i, o) {
                var n, s = e.length - 1;
                e.forEach(function(e, o) {
                    if (e.tabSelectShow && (n = e.tabSelectShow), e.id == a) {
                        if (o == s) i({
                            ind: 0,
                            listinid: 7,
                            tabShow: n
                        });
                        if (s - o >= 8) i({
                            ind: t,
                            listinid: t + 8,
                            tabShow: n
                        }); else i({
                            ind: o,
                            listinid: s + 1,
                            tabShow: n
                        });
                    }
                });
            });
        },
        tapClassDivGetind: function(t, e) {
            return new Promise(function(a, i) {
                t.forEach(function(t, i) {
                    t.id == e && a({
                        key: i,
                        info: t
                    });
                });
            });
        },
        tapClassDiv: function(a) {
            var o = this;
            return i(t.default.mark(function i() {
                var n, s, l, c, r, d, h, u, f, p, g, x, S;
                return t.default.wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        return s = a.currentTarget.dataset.ind, l = a.currentTarget.dataset.index, c = a.currentTarget.dataset.all, 
                        r = o.data.datas.list[l].second_list, d = c[s].id, r.forEach(function(t, e) {
                            t.tabSelectShow = "", t.id == d && (t.tabSelectShow = t.id);
                        }), o.setData((e(n = {}, "infoDatas[" + l + "]", c[s].components), e(n, "allDatas[" + l + "]", o.data.allDatas[l]), 
                        e(n, "datas.list[" + l + "].second_list", r), e(n, "bz", "a".concat(l)), n)), t.next = 9, 
                        o.tapClassDivGetind(r, d);

                      case 9:
                        if (h = t.sent, u = h.info.components, f = h.key, 0 != u.length) {
                            t.next = 17;
                            break;
                        }
                        return t.next = 15, o.updateHeight();

                      case 15:
                        p = t.sent, o.setData({
                            listHeight: p
                        });

                      case 17:
                        g = 0;

                      case 18:
                        if (!(g < u.length)) {
                            t.next = 37;
                            break;
                        }
                        if ("U_goods" != u[g].uikey) {
                            t.next = 33;
                            break;
                        }
                        return (x = {
                            page: 1,
                            decorate_id: o.data.page_id,
                            component_id: o.data.component_id,
                            component_key: "U_moretabcontrol"
                        }).component_info = {
                            list_key: l,
                            second_list_key: f,
                            components_key: g
                        }, x.component_info = JSON.stringify(x.component_info), wx.showLoading({
                            title: "加载中",
                            icon: "none"
                        }), t.next = 26, o.tapClassGet(x, l, s, g);

                      case 26:
                        return wx.hideLoading({
                            success: function(t) {}
                        }), t.next = 29, o.updateHeight();

                      case 29:
                        S = t.sent, o.setData({
                            listHeight: S
                        }), t.next = 34;
                        break;

                      case 33:
                        o.setData({
                            rightScrollTop: o.data.listHeight[l] + 10
                        });

                      case 34:
                        g++, t.next = 18;
                        break;

                      case 37:
                      case "end":
                        return t.stop();
                    }
                }, i);
            }))();
        },
        tapClassGet: function(t, a, i, n) {
            var s = this;
            return new Promise(function(i, l) {
                var c = s.selectComponent("#goodsListC".concat(a)), r = o.getNetAddresss("home-page.get-decorate-page");
                s.properties.store_id && (r += "&store_id=".concat(s.properties.store_id)), o._getNetWork({
                    url: r,
                    data: t,
                    success: function(t) {
                        var o;
                        1 == t.data.result && (s.data.infoDatas[a][n] && (s.setData((e(o = {}, "infoDatas[" + a + "][" + n + "].remote_data.list", t.data.data), 
                        e(o, "rightScrollTop", s.data.listHeight[a] + 10), o)), c.tabTwoContro(s.data.infoDatas[a][n].remote_data.list, a)));
                        i();
                    },
                    fail: function(t) {
                        console.log(t), wx.showToast({
                            title: t.msg,
                            icon: "none"
                        }), wx.hideLoading({
                            success: function(t) {}
                        });
                    }
                });
            });
        },
        onReadEnd: function(t) {
            var e = t.detail.index, a = this.createSelectorQuery();
            a.select("#goodsListC".concat(e)).boundingClientRect(), a.selectViewport().scrollOffset(), 
            a.exec(function(t) {
                if (console.log(t[0], t[1]), 0 != t[0].top) {
                    var e = 0;
                    if (t[1].scrollTop > t[0].top) {
                        if (!(t[0].top < 0)) return;
                        e = t[1].scrollTop + t[0].top - 70;
                    } else e = t[0].top;
                    wx.pageScrollTo({
                        scrollTop: e,
                        complete: function(t) {
                            console.log(t);
                        }
                    });
                }
            });
        },
        tapIntoSelect: function(t) {
            var e = "a".concat(t.currentTarget.dataset.ind);
            this.createSelectorQuery().selectViewport().scrollOffset().select("#".concat(e)).boundingClientRect().exec(function(t) {
                wx.pageScrollTo({
                    scrollTop: t[0].scrollTop + t[1].top + 20,
                    duration: 500
                });
            });
        },
        ondisplay: function(t) {
            var e = t.detail.index;
            t.detail.display ? e == this.data.intoSelect && this.setData({
                intoSelect: null
            }) : this.setData({
                intoSelect: e
            });
        },
        ondisplayListView1: function(t) {
            var a = t.detail.index, i = t.detail.display, o = t.detail.type, n = this.data.datas.list;
            n[a].childPos = "up" == o && !i, this.setData(e({}, "datas.list", n));
        },
        ondisplayListView: function(t) {
            var e = t.detail.index, a = t.detail.display, i = t.detail.type;
            this.getLeftHight(this.data.intoSelect), a && "up" == i ? this.setData({
                intoSelect: e
            }) : "up" == i && this.setData({
                intoSelect: e + 1
            });
        },
        onscroll: function(t) {},
        onLeftscroll: function(t) {
            t.detail.isFixed ? this.data.isLeftFixed || this.setData({
                isLeftFixed: t.detail.isFixed
            }) : this.data.isLeftFixed && this.setData({
                isLeftFixed: t.detail.isFixed
            });
        },
        bindscroll: function(t) {
            var e = this.checkarr(t.detail.scrollTop, this.data.listHeight);
            this.data.intoSelect != e && this.setData({
                intoSelect: e
            }), console.log(t.detail.scrollTop, this.data.intoSelect);
        },
        checkarr: function(t, e) {
            for (var a, i = 0; i < e.length; i++) t >= e[i] && t < e[i + 1] && (a = i);
            return t >= e[a] + 50 && t < e[a + 1] - 100 ? this.data.childPos || this.setData({
                childPos: !0
            }) : this.data.childPos && this.setData({
                childPos: !1
            }), a;
        },
        resultMrh: function(t) {
            for (var e = "", a = 0; a < this.data.datas.list.length; a++) t[a].top <= 0 && (e = a);
            return String(e);
        },
        setIntoselect: function(t) {
            "[object Object]" !== Object.prototype.toString.call(t) ? this.setData({
                intoSelect: t
            }) : this.setData({
                intoSelect: 0
            }), console.log(t, "intoSelect", "[object Object]" === Object.prototype.toString.call(t), this.data.intoSelect);
        },
        imgload: function(t) {
            this.methodDragend();
        },
        updateHeight: function() {
            var t = this;
            return new Promise(function(e, a) {
                var i = t.createSelectorQuery();
                i.selectAll(".rightScrollViewNode").boundingClientRect(), i.exec(function(a) {
                    var i = a[0], o = 0;
                    t.data.listHeight = [ 0 ], i.map(function(e) {
                        o += e.height, t.data.listHeight.push(o);
                    }), e(t.data.listHeight);
                });
            });
        },
        methodDragend: function(t) {
            var e = this, a = this.createSelectorQuery();
            a.selectAll(".rightScrollViewNode").boundingClientRect(), a.exec(function(t) {
                var a = t[0], i = 0;
                e.data.listHeight = [ 0 ], a.map(function(t) {
                    i += t.height, e.data.listHeight.push(i);
                }), e.setData({
                    listHeight: e.data.listHeight
                });
            });
        },
        leftPos: function() {
            var t = this;
            this.createSelectorQuery().selectAll("#tabNode").boundingClientRect().exec(function(e) {
                if (e[0][0].top <= 0) {
                    if (Math.abs(e[0][0].top) <= 30) return void (t.data.leftPosShow && t.setData({
                        leftPosShow: !1
                    }));
                    t.data.leftPosShow || t.setData({
                        leftPosShow: !0
                    });
                }
            });
        },
        getRightFiexd: function(t, e) {
            var a = e[t].height, i = Math.abs(e[t].top);
            return console.log("子元素高度", a), console.log("元素滚动距离", i), i < 114 ? (console.log("xxxxxxxxxxxxxxxx11"), 
            !1) : i >= 114 && i <= a - 300 ? (console.log("xxxxxxxxxxxxxxxx22"), !0) : void 0;
        },
        getLeftHight: function(t) {
            var e = this;
            this.createSelectorQuery().selectAll(".leftinto").boundingClientRect().exec(function(a) {
                var i = a[0];
                t != e.data.intoSelect && (t <= 4 ? e.setData({
                    leftScrollTop: 0
                }) : i[e.data.intoSelect] && e.setData({
                    leftScrollTop: i[e.data.intoSelect].height * t - 130
                }));
            });
        }
    }
});